package cz.semjob.document.annotation;

import java.util.List;

import cz.semjob.common.util.TextUtil;
import cz.semjob.document.annotation.metadata.Entity;
import cz.semjob.document.processing.DocumentWord;
import cz.semjob.document.util.DocumentUtil;

public class RelationWordsPair {
	
	private Entity entity1;
	
	private Entity entity2;
	
	private List<DocumentWord> relationWord1;
	
	private List<DocumentWord> relationWord2;

	public RelationWordsPair(List<DocumentWord> relationWord1,
			List<DocumentWord> relationWord2, Entity entity1, Entity entity2) {
		super();
		this.relationWord1 = relationWord1;
		this.relationWord2 = relationWord2;
		if (entity1 == null || entity2 == null) {
			throw new AssertionError("One of entities is null");
		}
		this.entity1 = entity1;
		this.entity2 = entity2;
		
	}
	
	public RelationWordsPair(LabeledWords relationWord1, LabeledWords relationWord2) {
		super();
		this.relationWord1 = relationWord1.getWords();
		this.relationWord2 = relationWord2.getWords();
		this.entity1 = relationWord1.getLabel();
		this.entity2 = relationWord2.getLabel();
		if (entity1 == null || entity2 == null) {
			throw new AssertionError("One of entities is null");
		}
		
	}

	public List<DocumentWord> getRelationWord1() {
		return relationWord1;
	}

	public List<DocumentWord> getRelationWord2() {
		return relationWord2;
	}

	public Entity getEntity1() {
		return entity1;
	}

	public Entity getEntity2() {
		return entity2;
	}

	@Override
	public String toString() {
		return "RelationWordsPair [entity1=" + entity1 + ", entity2=" + entity2
				+ ", relationWord1=" + relationWord1 + ", relationWord2="
				+ relationWord2 + "]";
	}
	
	public String toPrettyString() {
		return DocumentUtil.printWords(relationWord1) + "("+ entity1.getName() + ") " +  DocumentUtil.printWords(relationWord2) + "("+ entity2.getName() + ")"; 
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((entity1 == null) ? 0 : entity1.hashCode());
		result = prime * result + ((entity2 == null) ? 0 : entity2.hashCode());
		result = prime * result
				+ ((relationWord1 == null) ? 0 : relationWord1.hashCode());
		result = prime * result
				+ ((relationWord2 == null) ? 0 : relationWord2.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RelationWordsPair other = (RelationWordsPair) obj;
		if (entity1 == null) {
			if (other.entity1 != null)
				return false;
		} else if (!entity1.equals(other.entity1))
			return false;
		if (entity2 == null) {
			if (other.entity2 != null)
				return false;
		} else if (!entity2.equals(other.entity2))
			return false;
		if (relationWord1 == null) {
			if (other.relationWord1 != null)
				return false;
		} else if (!relationWord1.equals(other.relationWord1))
			return false;
		if (relationWord2 == null) {
			if (other.relationWord2 != null)
				return false;
		} else if (!relationWord2.equals(other.relationWord2))
			return false;
		return true;
	}
	
	


	
	
	
	
	

}
